﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace yiwei.Repository.Migrations
{
    public partial class InitialCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Module",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    CascadeId = table.Column<string>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    ParentId = table.Column<string>(nullable: true),
                    ParentName = table.Column<string>(nullable: true),
                    Url = table.Column<string>(type: "varchar(200)", nullable: true),
                    IsLeaf = table.Column<bool>(nullable: false),
                    IsAutoExpand = table.Column<bool>(nullable: false),
                    IconName = table.Column<string>(type: "varchar(200)", nullable: true),
                    Status = table.Column<int>(nullable: false),
                    Vector = table.Column<string>(type: "varchar(200)", nullable: true),
                    SortNo = table.Column<int>(nullable: false),
                    Code = table.Column<string>(type: "varchar(200)", nullable: false),
                    IsSys = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Module", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Relevance",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Description = table.Column<string>(nullable: true),
                    Key = table.Column<string>(type: "varchar(200)", nullable: true),
                    OperatorId = table.Column<Guid>(nullable: false),
                    FirstId = table.Column<Guid>(nullable: false),
                    SecondId = table.Column<Guid>(nullable: false),
                    ExtendInfo = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Relevance", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Role",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Name = table.Column<string>(type: "varchar(200)", nullable: false),
                    Description = table.Column<string>(type: "varchar(200)", nullable: false),
                    Status = table.Column<int>(nullable: false),
                    CreateId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Role", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "User",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    Account = table.Column<string>(type: "varchar(100)", nullable: false),
                    Password = table.Column<string>(type: "varchar(100)", nullable: false),
                    Name = table.Column<string>(type: "varchar(100)", nullable: false),
                    Remark = table.Column<string>(type: "varchar(200)", nullable: false),
                    Sex = table.Column<int>(nullable: false),
                    Status = table.Column<int>(nullable: false),
                    LoginCount = table.Column<int>(nullable: false),
                    lastLoginTime = table.Column<DateTime>(nullable: false),
                    CreateId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ModuleElement",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    IsDelete = table.Column<bool>(nullable: false),
                    CreateTime = table.Column<DateTime>(nullable: false),
                    DomId = table.Column<string>(type: "varchar(200)", nullable: false),
                    Name = table.Column<string>(type: "varchar(200)", nullable: false),
                    Attr = table.Column<string>(type: "varchar(200)", nullable: true),
                    Icon = table.Column<string>(nullable: true),
                    Class = table.Column<string>(type: "varchar(200)", nullable: true),
                    Remark = table.Column<string>(type: "varchar(200)", nullable: true),
                    Sort = table.Column<int>(nullable: false),
                    ModuleId = table.Column<Guid>(nullable: false),
                    TypeId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ModuleElement", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ModuleElement_Module_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "Module",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "Index_Code",
                table: "Module",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ModuleElement_ModuleId",
                table: "ModuleElement",
                column: "ModuleId");

            migrationBuilder.CreateIndex(
                name: "Index_Name",
                table: "Role",
                column: "Name",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "Index_Account",
                table: "User",
                column: "Account",
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ModuleElement");

            migrationBuilder.DropTable(
                name: "Relevance");

            migrationBuilder.DropTable(
                name: "Role");

            migrationBuilder.DropTable(
                name: "User");

            migrationBuilder.DropTable(
                name: "Module");
        }
    }
}
